package com.gitee.liang521.generate.api.generate;

import com.gitee.liang521.generate.api.config.GenerateProperties;
import com.github.xiaoymin.knife4j.core.util.StrUtil;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * @author liang zai
 * @date 2021/9/16 18:22
 * @description
 */
@Component
public class ClassGenerate extends BaseGenerate{
    @Override
    public String getDirPath(String tableNameCameCase, GenerateProperties.Template generateTemplate, String model) {
        String path =
                "src" + File.separator +"main" + File.separator + "java" +File.separator +this.getPackageName().replace(".", File.separator);
        if (StrUtil.isNotBlank(model)){
            path += File.separator + model.replace(".", "/");

        }
        path += File.separator + generateTemplate.getDir();
        if(generateTemplate.getNeedTablePackage() != null && generateTemplate.getNeedTablePackage()){
            path += File.separator + tableNameCameCase.toLowerCase();
        }
        return path;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        GenerateFactory.register(GenerateFactory.CLASS_GENERATE_KEY, this);
    }
}
